<template>
	<view class="">
		<view class="app">
			<view class="countdown" :style="{ top: navHeight }" v-if="countdownNum > 0" @click="jump">{{ countdownNum }}s{{ countTip }}</view>
			<image :src="swiperList[0].activityImgUrl"></image>
		</view>
		<view class="" style="display: flex;align-items: center;justify-content: center;">
			<image :src="logoList[0].activityImgUrl" style="width:200rpx" mode="widthFix"></image>
		</view>
	</view>
</template>
 
<script>
	import {
		userIsLogin,
		checkPracticeStudentBindingState,
		getRecommen
	} from '../../utils/api.js';
export default {
	data() {
		return {
			countdownNum: 3,
			swiperList:[],
			logoList:[],
			timer: null,
			countTip: '跳过',
			navHeight: 200,//胶囊高度
			nameTitle:'',
			bgType:'',
			logoType:'',
		};
	},
	onLoad(options) {
		if(options.logoType){
			this.logoType=options.logoType
			console.log(this.logoType);
		}
		if(options.bgType){
			this.bgType=options.bgType
			console.log(this.bgType);
		}
		
		this.computeHeight();
		this.getswiperList()
	},
	mounted() {
		this.getCode();
	},
	beforeDestroy() {
		clearInterval(this.timer); // 清除定时器
		this.timer = null;
	},
	methods: {
			getswiperList() {
				let datas = {
					businessId: -1
				};
				getRecommen(datas).then(res => {
					if (res.code == 200) {
						if(this.bgType){
							this.swiperList= res.body.filter(itm => itm.type ===this.bgType );
						}else{
							this.swiperList= res.body.filter(itm => itm.type === 'homeOne');
						}
						if(this.logoType){
							this.logoList= res.body.filter(itm => itm.type === this.logoType);
						}else{
							this.logoList= res.body.filter(itm => itm.type === 'logo');
						}
						
						
						
					}
				});
			},
		//计算胶囊的高度
		computeHeight() {
			// #ifdef APP-PLUS
			this.navHeight = 120 + 'rpx';
			uni.getSystemInfo({
				success: function (res) {
					console.log(res)
				}
			});
			// #endif
 
			// #ifdef H5
			this.navHeight = 120 + 'rpx'; 
			// #endif
			
			// 运行在小程序
			//#ifdef MP-WEIXIN
			uni.getSystemInfo({
				success: postdata => {
					let custom = uni.getMenuButtonBoundingClientRect();
					console.log(custom, 'custom');
					//导航栏高度 = 状态栏到胶囊的间距（胶囊距上距离-状态栏高度） * 2 + 胶囊高度 + 状态栏高度。
					// 100rpx='当前盒子的高度60rpx+距状态栏的高度40rpx'
					this.navHeight = custom.bottom + custom.top - postdata.statusBarHeight + 100 + 'rpx';
					console.log(this.navHeight, 'navHeight');
				}
			});
			//#endif
		},
		getCode() {
			//倒计时
			this.timer = setInterval(() => {
				if (this.countdownNum > 1) {
					this.countdownNum--;
				} else {
					console.log(789789);
					userIsLogin().then(sult => {
						if (sult.body.isLogin) {
							checkPracticeStudentBindingState().then(res => {
								if (res.body) {
									if (res.body.enable == 1) {
										uni.switchTab({
											url: '/pages/index/index'
										});
									} else {
		
										clearInterval(this.timer)
										uni.showModal({
											title: '提示',
											content: '当前账号已被禁用',
											confirmColor: '#ee6666', //确定字体颜色
											showCancel: false, //没有取消按钮的弹框
											buttonText: '确定',
											success: function(res) {
												if (res.confirm) {
													uni.removeStorageSync(
														'studentInfo');
													// uni.removeStorageSync('userInfo');
													// uni.removeStorageSync('__ddminiUserOpenid');
													uni.removeStorageSync(
														'__DC_STAT_UUID');
													uni.redirectTo({
														url: '/pages/login/login'
													});
													console.log('用户点击确定');
												} else if (res.cancel) {
													console.log('用户点击取消');
												}
											}
										});
									}
								} else {
									uni.removeStorageSync('studentInfo');
									// uni.removeStorageSync('userInfo');
									// uni.removeStorageSync('__ddminiUserOpenid');
									uni.removeStorageSync('__DC_STAT_UUID');
									uni.redirectTo({
										url: '/pages/login/login'
									});
								}
							});
						} else {
							uni.removeStorageSync('studentInfo');
							uni.removeStorageSync('userInfo');
							uni.removeStorageSync('__ddminiUserOpenid');
							uni.removeStorageSync('__DC_STAT_UUID');
							uni.redirectTo({
								url: '/pages/login/login'
							});
		
						}
					});
		
				}
			}, 1000);
		},
		jump() {
			if (this.countdownNum <= 5) {
				userIsLogin().then(sult => {
					if (sult.body.isLogin) {
						checkPracticeStudentBindingState().then(res => {
							if (res.body) {
								if (res.body.enable == 1) {
									uni.switchTab({
										url: '/pages/index/index'
									});
								} else {
		
									clearInterval(this.timer)
									uni.showModal({
										title: '提示',
										content: '当前账号已被禁用',
										confirmColor: '#ee6666', //确定字体颜色
										showCancel: false, //没有取消按钮的弹框
										buttonText: '确定',
										success: function(res) {
											if (res.confirm) {
												uni.removeStorageSync('studentInfo');
												// uni.removeStorageSync('userInfo');
												// uni.removeStorageSync('__ddminiUserOpenid');
												uni.removeStorageSync('__DC_STAT_UUID');
												uni.redirectTo({
													url: '/pages/login/login'
												});
												console.log('用户点击确定');
											} else if (res.cancel) {
												console.log('用户点击取消');
											}
										}
									});
								}
								// uni.switchTab({
								// 	url: '/pages/index/index'
								// });
							} else {
								uni.removeStorageSync('studentInfo');
								uni.removeStorageSync('userInfo');
								uni.removeStorageSync('__ddminiUserOpenid');
								uni.removeStorageSync('__DC_STAT_UUID');
								uni.redirectTo({
									url: '/pages/login/login'
								});
							}
						});
					} else {
						uni.removeStorageSync('studentInfo');
						uni.removeStorageSync('userInfo');
						uni.removeStorageSync('__ddminiUserOpenid');
						uni.removeStorageSync('__DC_STAT_UUID');
						uni.redirectTo({
							url: '/pages/login/login'
						});
		
					}
				});
			}
		}
	}
};
</script>
 
<style lang="scss" scoped>
* {
	margin: 0;
	padding: 0;
}
 
.app {
	width: 750rpx;
	height: 80vh;
	position: relative;
	.countdown {
		position: absolute;
		z-index: 99;
		top: 0;
		right: 40rpx;
		width: 120rpx;
		height: 60rpx;
		border-radius: 8rpx;
		background-color: rgba(0, 0, 0, 0.6);
		color: #fff;
		text-align: center;
		line-height: 60rpx;
	}
	image {
		width: 100%;
		height: 100%;
	}
}
</style>